package com.fjzzct.report.utils;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

public class LogHelper {
    /// <summary>
    /// 记录错误日志
    /// 使用时请确保调用方指定了log4net的配置文件并且配置文件中存在<logger name="logerror">及其对应的Appender
    /// </summary>
    /// <param name="message"></param>
    /// <param name="ex"></param>
    public static void WriteErrorLog(Exception ex) {
        Logger log = Logger.getLogger("logerror");
        log.error(ex,ex.fillInStackTrace());
    }

    public static void WriteErrorLog(String msg)
    {
        Logger log = Logger.getLogger("logerror");
        log.error(msg);

    }

    /// <summary>
    /// 记录一些基本信息
    /// 使用时请确保调用方指定了log4net的配置文件并且配置文件中存在<logger name="loginfo">及其对应的Appender
    /// </summary>
    /// <param name="message"></param>
    public static void WriteInfoLog(String message)
    {
    	Logger log = Logger.getLogger("loginfo");
        log.info(message);
    }

    public static void WriteDebugLog(String message)
    {
    	Logger log = LogManager.getLogger("logdebug");
        log.debug(message);
    }
    /// <summary>
    /// 获取异常的各种信息
    /// </summary>
    /// <param name="ex"></param>
    /// <returns></returns>
//    private static string GetExceptionInfo(Exception ex)
//    {
//        string targetSite = ex.TargetSite != null ? ex.TargetSite.ToString() : "";
//
//        return string.Format("程序集名称：{0}\r\n发生异常的方法：{1}\r\n错误信息：{2}\r\n堆栈信息：\r\n{3}",
//                             ex.Source, targetSite, ex.Message, ex.StackTrace);
//    }
}
